package com.example.test06thread.test.synch;

public class DeadLock2 {
    static Object o2 = new Object();
    static Object o1 = new Object();
    public static void main(String[] args) {
        DeadLock2 deadLock2 = new DeadLock2();
        new Thread(deadLock2::t1).start();
        new Thread(deadLock2::t2).start();
    }

    public void t1(){
        synchronized (o1){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("access to o1,ready to get o2");
            synchronized (o2){

            }
        }
    }

    public void t2(){
        synchronized (o2){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("access to o2,ready to get o1");
            synchronized (o1){

            }
        }
    }
}
